﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Matrix
{
    class Program
    {
        
        public static void Main(string[] args)
        {
            MatrixMult m = new MatrixMult();
            const int a = 3;
            const int b = 4;
            const int c = 5;
            int[,] m1 = m.CreateMatrixWithRandomValues(a,b);
            int[,] m2 = m.CreateMatrixWithRandomValues(b,c);

            m.ViewMatrix(m1);
            m.ViewMatrix(m2);
            
            
            m.ViewMatrix(m.MultiplyMatrix(m1,m2));


             Console.ReadKey();
    
           
        }

        


    }
    class MatrixMult
    {

        Random _random = new Random(); 

        public int[,] CreateMatrixWithRandomValues(int i, int j) 
        {

            int[,] matrix = new int[i, j];
            for (int a = 0; a < i; a++)
                for (int b = 0; b < j; b++)
                {
                    matrix[a, b] = _random.Next(0,100);
                }
                    return matrix;
        }

        public int[,] MultiplyMatrix(int[,] matrix1, int[,] matrix2) 
        {
            int a = matrix1.GetLength(0);
            int b = matrix1.GetLength(1);
            int c = matrix2.GetLength(1);            
            int[,] matrixResult = new int[a, c];
            int x=0;
            for (int i = 0; i < a; i++)
            {
                for (int k = 0; k < c; k++)
                {
                    for (int j = 0; j < b; j++)
                    {
                        x += matrix1[i, j] * matrix2[j, k];
                    }
                    matrixResult[i, k] = x;
                    x = 0;
                }
            }

                return matrixResult;
        }

        public void ViewMatrix(int[,] matrix)
        {
            Console.WriteLine("\n\n");
            for (int i = 0; i < matrix.GetLength(0); i++)
            {     for (int j = 0; j < matrix.GetLength(1); j++)
                {
                    Console.Write("\t"+matrix[i, j] + "\t");
                }
                Console.Write("\n\n");
            }
            Console.WriteLine("\n\n");
        }
    }

}
